/**
 * 账单模型
 * 对应数据库中的bills表
 */
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = require('./User');
const Category = require('./Category');

const Bill = sequelize.define('bills', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: '账单ID'
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '用户ID'
  },
  category_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '分类ID'
  },
  amount: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '金额'
  },
  type: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '类型：income-收入，expense-支出'
  },
  remark: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: '备注'
  },
  bill_date: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '账单日期，包含时间'
  },
  create_time: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  }
}, {
  // 模型选项
  tableName: 'bills',
  timestamps: false // 不使用createdAt和updatedAt字段
});

// 关联关系在models/index.js中统一定义

module.exports = Bill;